﻿using System;
using System.Data;
using System.Web.UI.WebControls;

using TempEmployees.BLL.Database;

namespace TempEmployees.Web
{
    public partial class GridViewDepartmentStatus : BaseGridView
    {
        private static readonly int COLUMN_FIELD_BUDGET_ID = 1;
        private static readonly int COLUMN_INITIAL_BUDGET = 3;
        private static readonly int COLUMN_STATIC_BALANCE = 4;
        private static readonly int COLUMN_CURRENT_BALANCE = 5;
        private static readonly int[] budgetColumns = {
            COLUMN_INITIAL_BUDGET,
            COLUMN_STATIC_BALANCE,
            COLUMN_CURRENT_BALANCE };

        public void SetGridView(Filters filters)
        {
            GridViewDataTable = new DataTable();

            DbServices.FillDepartmentsGridView(GridViewDataTable, filters);

            SetGridView();
        }

        protected void ViewBudgets_RowCreated(object sender, GridViewRowEventArgs e)
        {
            //hide the EmployerBudgetID column
            if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[COLUMN_FIELD_BUDGET_ID].CssClass = "hiddencol";
            }
        }

        public int GetSelectedLabId()
        {
            int id;
            GridViewRow row = ViewBudgets.Rows[ViewBudgets.SelectedIndex];
            return int.TryParse(row.Cells[COLUMN_FIELD_BUDGET_ID].Text, out id) ? id : -1;
        }

        protected void ViewBudgets_DataBound(object sender, EventArgs e)
        {
            SetBalanceColumns(budgetColumns);
        }

        protected override GridView GetGridView()
        {
            return ViewBudgets;
        }

        protected override ObjectDataSource GetDataSource()
        {
            return DepartmentsStatusDataSource;
        }
    }
}